import datetime


class PackagedPageItemInfo:
    def __init__(self, _id: int, _thumbnail_url: str, _create_date: datetime.datetime):
        self.id = _id
        self.thumbnail_url = _thumbnail_url
        self.create_date = _create_date

    def __repr__(self) -> str:
        return f'PixivID: {self.id} {{\n' \
               f'    ThumbURL(250x250): {self.thumbnail_url},\n' \
               f'    CreateDate: {self.create_date}\n' \
               f'}}'


class PackagedPageInfo:
    def __init__(self, _search_keyword: str, _page_index: int, _artworks: list[PackagedPageItemInfo], _total: int):
        self.search_keyword = _search_keyword
        self.page_index = _page_index
        self.artworks: list[PackagedPageItemInfo] = _artworks
        self.total = _total
        self.latest_create_date = self.get_latest_create_date()

    def __repr__(self) -> str:
        return f'Page {self.page_index} of `{self.search_keyword}` {{\n' \
               f'    Total: {self.total}, \n' \
               f'    LatestCreateDate: {self.latest_create_date}\n' \
               f'}}'

    def get_latest_create_date(self) -> datetime.datetime:
        res = datetime.datetime(year=2000, month=1, day=1)
        for each in self.artworks:
            if (res.year < each.create_date.year) or (
                    res.year == each.create_date.year and (
                    res.month < each.create_date.month or (
                    res.month == each.create_date.month and
                    res.day < each.create_date.day))):
                res = each.create_date
        return res


class PackagedPicInfo:
    def __init__(self, _is_r18: bool, _id: int, _thumbnail_url: str,
                 _upload_date: int, _like_num: int, _is_ai: bool):
        self.id = _id
        self.thumbnail_url = _thumbnail_url
        self.is_r18 = _is_r18
        self.like_num = _like_num
        self.upload_date = _upload_date
        self.is_ai = _is_ai

    def __repr__(self) -> str:
        return f'PixivID: {self.id} {{\n' \
               f'    IsR18: {self.is_r18},\n' \
               f'    ThumbURL: {self.thumbnail_url},\n' \
               f'    UploadDate: {self.upload_date},\n' \
               f'    BookmarkCount: {self.like_num},\n' \
               f'    AICreated: {self.is_ai}\n' \
               f'}}'


class PackagedSearchInfo:
    def __init__(
            self,
            _total_artwork_num: int, _total_page_num: int, _artwork_in_this_page: int,
            _latest_create_date: datetime.datetime):
        self.total_artwork_num = _total_artwork_num
        self.total_page_num = _total_page_num
        self.artwork_in_this_page = _artwork_in_this_page
        self.latest_create_date = _latest_create_date

    def __repr__(self):
        return f'{{\n' \
               f'  self.total_artwork_num = {self.total_artwork_num}\n' \
               f'  self.total_page_num = {self.total_page_num}\n' \
               f'  self.artwork_in_this_page = {self.artwork_in_this_page}\n' \
               f'  self.latest_create_date = {self.latest_create_date}\n' \
               f'}}'
